<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>唯爱薇o朝圣之路v-for课程</title>
    <script src="https://unpkg.com/vue@next"></script>
</head>
<body>
    <h1>唯爱薇o朝圣之路-V-for实验</h1>
    <hr/>
    <div id="app">




    </div>
    
</body>
<script>
    Vue.createApp(
        {
            data() {

                return {
                    //---此处添加变量名称
                    courseName:'',
                    courses: [],
                    //课程对象
                    courseObject:{
                        devops:'运维开发课程',
                        golang:'Golang语言课',
                        python:'Python语言课'
                    },                    
                    relatives: ["liumin","liuchen","liuxiaozhen","liulihua","liuxiaonian","liujianhua","liudongliang"]
                }
                
            },
            methods: {
                addCourse() {
                    this.courses.push(this.courseName)
                    this.courseName=""
                }
            },
            //注意key与template在for循环中的意义
            template: `<div>
                <input v-model="courseName" />
                <hr />
                <button v-on:click="addCourse">添加课程</button>
                <hr />
                
                <ul>
                    <li v-for="(course,index) of courses"> [{{ index }}] -- {{ course }} </li>
                </ul>
                
                <hr />
                
                <ul>
                    <li 
                
                        v-for="(relative,index) in relatives"
                        :key = "index + relative"
                    > 
                    
                        [{{ index }}] -- {{ relative }} 
                
                    </li>
                </ul>
                
                <hr />
                
                <ul>
                    <li 
                
                        v-for="(course,key,index) in courseObject"
                        :key = "key"
                    > 
                    
                        [{{ index }}] -[{{ key }}]- {{ course }} 
                
                    </li>
                </ul>
                
                <hr />
                <p>刘敏(liumin)不是亲戚，不显示liumin，但不能改变源数据relatives。</p>
                <hr />
                <ul>
                    <template  v-for="(relative,index) in relatives" :key = "index + relative" >
                        <li  v-if="relative != 'liumin'" > 
                        
                            [{{ index }}] - {{ relative }} 
                    
                        </li>
                    </template>
                </ul>                     

            </div>`
        }
    ).mount("#app")
</script>
</html>